/*
 * 产品搜索
 * @Author: ljb
 * @Date: 2018-03-27 17:51:07
 * @Last Modified by: ljb
 * @Last Modified time: 2018-07-25 17:57:39
 */
<template>
	<Form
		ref="formInline"
		inline
		@keydown.native.enter.prevent="confirmSearch">

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('product.customer')"
			prop="customer_id">
			<Select
				v-model="formValidate.customer_id"
				clearable
				filterable>
				<Option
					v-for="( value , key ) in customers"
					:value="key + ''"
					:key="key">{{ value }}</Option>
			</Select>
		</Form-item>

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('product.is_sale')"
			prop="is_sale">
			<Select
				v-model="formValidate.is_sale"
				:style="{width: '100px'}"
				clearable>
				<Option
					v-for="status in sale_status"
					:value="status.value"
					:key="status.value">{{ status.label }}</Option>
			</Select>
		</Form-item>

		<Form-item>
			<Button
				type="primary"
				@click="confirmSearch">
				{{ $t('common.search') }}
			</Button>
		</Form-item>

	</Form>
</template>
<script>

export default {

	name: 'ProductSearchForm',

	props: {
		customers: {
			type: Object,
			default() {
				return {};
			},
		},
	},

	data() {
		return {
			sale_status: [ // 是都上架
				{
					label: this.$t('product.no'),
					value: '0',
				},
				{
					label: this.$t('product.yes'),
					value: '1',
				},
			],
			formValidate: {

				customer_id: '', // 商家ID

				is_sale: '', // 是否上架

			}, // 搜索框的对象参数
		};
	},

	computed: {
		isChinese() {
			return this.$i18n.locale === 'zh-CN';
		},
	},

	mounted() {

	},

	methods: {

		/**
         * 确认搜索
         * @return {undefined}
         */
		confirmSearch() {
			const param = {

				customer_id: this.formValidate.customer_id,

				is_sale: this.formValidate.is_sale,

			};

			this.$emit('search', param);
		},

	},

};

</script>
